﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace sgsBase
{
	public class SgsMasterPage : System.Web.UI.MasterPage
	{
		public SgsGlobal Gl;

		protected void Page_Load(object sender, EventArgs e)
		{
			//Gl = (SgsGlobal)HttpContext.Current.ApplicationInstance;

			//PageLoad(sender, e);
		}

		protected virtual void PageLoad(object sender, EventArgs e)
		{

		}

		protected void Page_PreRender(object sender, EventArgs e)
		{
			Gl = (SgsGlobal)HttpContext.Current.ApplicationInstance;

			PagePreRender(sender, e);
		}

		protected virtual void PagePreRender(object sender, EventArgs e)
		{

		}

		public void SetOnLoad(string func)
		{ 
			HtmlGenericControl BodyID;
			BodyID = (HtmlGenericControl)Page.Controls[0].FindControl("BodyID");

			if (BodyID == null)
				return;

			string onload = BodyID.Attributes["onload"];
			if (onload != null)
			{
				if (onload == func)
					return;
				// this line would be used to append the functions, but maybe they should be cleared and reset
				//func = onload + ";" + func;
			}
			BodyID.Attributes.Add("onload", func);
		}

	}
}
